# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# contributers: Zach Bacon <zachbacon@budgiemedia.rocks>

_realname=SDL2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.28.2
pkgrel=1
pkgdesc="A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard (Version 2) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://libsdl.org"
license=("spdx:Zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-vulkan")
source=("https://libsdl.org/release/SDL2-${pkgver}.tar.gz"
        005-sdl-config-win-paths.patch)
sha256sums=('64b1102fa22093515b02ef33dd8739dee1ba57e9dbba6a092942b8bbed1a1c5e'
            'f126854e9edb57f92325cc6d004072ff1e08136e0c334ed2bb163db5893a8692')
validpgpkeys=('1528635D8053A57F77D1E08630A59377A7763BE6') # Sam Lantinga

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  # Fixes sdl-config https://github.com/msys2/MINGW-packages/issues/9881
  patch -p1 -i ${srcdir}/005-sdl-config-win-paths.patch
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DSDL_VULKAN=ON \
    -DSDL_TEST=ON \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
}
